/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ipodhash;

import ipodhash.beans.Arquivo;
import ipodhash.beans.Musica;
import ipodhash.beans.Serializa;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.farng.mp3.MP3File;
import org.farng.mp3.TagException;

/**
 *
 * @author rooke
 */
public class TesteImportacao {

    /**
     * @param args the command line arguments
     */
    public static void main2(String[] args) {
        File pastao = new File("/home/rooke/teste");
        File[] arquivosMp3 = pegaArquivosMp3(pastao);

        ArrayList<Musica> musicas = new ArrayList<Musica>();
        int hash;

        for (File arquivoMp3 : arquivosMp3) {
            try {
                MP3File mp3 = new MP3File(arquivoMp3);
                Musica musica = new Musica();
                musica.setAlbum(mp3.getID3v1Tag().getAlbum());
                musica.setArtista(mp3.getID3v1Tag().getArtist());
                musica.setTitulo(mp3.getID3v1Tag().getTitle());
                musica.setChave(musica.getArtista(), musica.getAlbum());

                musicas.add(musica);

                //hash = Integer.parseInt(musica.getChave())%99;
                hash = (int) (Math.random() * 100);
                System.out.println(musica.getChave());
                musica.getChave();
                

                Arquivo.importarComHash(arquivoMp3, hash, 1);

            } catch (Exception ex){
                 Logger.getLogger(TesteImportacao.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        try {
            Serializa.serializaArrayListMusica(musicas,1);
        } catch (Exception ex) {}

        //System.out.println("oioio");

    }

    public static File[] pegaArquivosMp3(File pasta) {
        
        FileFilter ff = new FileFilter() {
            public boolean accept(File dir) {
                return dir.getName().toLowerCase().endsWith(".mp3");
            }
        };

        return pasta.listFiles(ff);
    }
}
